package com.myTest.sqlSession;

import com.myTest.config.XMLConfigBuilder;
import com.myTest.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {
    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        //第一步 使用dom4j解析配置文件，并封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.paresConfig(inputStream);

        //第二步 创建SqlSessionFactory:工厂类：生产sqlSession:会话对象
        SqlSessionFactory sqlSessionFactory = new DefaultSqlSessionFactory(configuration);

        return sqlSessionFactory;
    }
}
